<?php

namespace App\Http\Controllers\v1;

use App\Model\BaseModel;
use App\Model\CardCategoryModel;
use App\Model\CardModel;
use App\Model\TopicFocusModel;
use App\Model\UserModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Validator;

/**
 * 查询分类话题
 * Class TopicController
 * @package App\Http\Controllers\v1
 */
class TopicController extends BaseController
{

    /**
     * 查询分类基础数据
     * @param cardId 分类id
     * @param Request $request
     * @return TopicController
     */
    public function getTopicDate(Request $request){

        $cardId = $request ->get('cardId');//话题分类id

        $res  = ( new  CardCategoryModel()) ->getTopicDate($cardId);

        if($res['code']){
            return $this -> success('查询数据成功！',$res['data']);
        }else{
            return $this -> error('查询数据失败！',$res['data']);
        }



    }

    /**
     * 话题加入总计
     * @param Request $request
     * @return TopicController
     */
    public function getALLJoinDate(Request $request){

        $topic_id = $request ->get('topic_id');

        if(empty($topic_id)){
           return $this ->success('缺少参数！');
        }

        $res  = ( new TopicFocusModel()) ->getALLJoinDate($topic_id);

        if($res['code']){
            return $this -> success('查询数据成功！',$res['data']);
        }else{
            return $this -> error('查询数据失败！',$res['data']);
        }



    }

    /**
     * 话题发帖总数
     * @param Request $request
     * @return TopicController
     */
    public function getSendPasteDate(Request $request){

        $cardId = $request ->get('cardId');//话题分类id

        if(empty($cardId)){
            return $this -> error('缺少参数！');
        }

        $res  = ( new  CardModel()) ->getSendPasteDate($cardId);

        if($res['code']){
            return $this -> success('查询数据成功！',$res['data']);
        }else{
            return $this -> error('查询数据失败！',$res['data']);
        }

    }

    /**
     * 话题关注状态
     * @param Request $request
     * @return TopicController
     */

    public function getTopicFocusStatue(Request $request){

        $topic_id = $request ->get('topic_id');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

        if(empty($topic_id)){
            return $this ->error('缺少参数！');
        }

        $res  = ( new  TopicFocusModel()) ->getTopicFocusStatue($uuid,$topic_id);

        if($res['code']){
            return $this -> success('查询数据成功！',$res['data']);
        }else{
            return $this -> error('查询数据失败！',$res['data']);
        }

    }

    /**
     * 关注话题
     * @param Request $request
     * @return TopicController
     */
    public function SaveFocusTopic(Request $request){

        $topic_id = $request ->get('topic_id');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

        if(empty($topic_id)){
            return $this ->error('缺少参数！');
        }

        $res  = ( new  TopicFocusModel()) ->SaveFocusTopic($uuid,$topic_id);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }

    }

    /**
     * 取消关注话题
     * @param Request $request
     * @return TopicController
     */
    public function deletedFocusTopic(Request $request){
        $topic_id = $request ->get('topic_id');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

        if(empty($topic_id)){
            return $this ->error('缺少参数！');
        }


        $res  = ( new  TopicFocusModel()) ->deletedFocusTopic($uuid,$topic_id);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }
    }


    /**
     * 相关话题类容话题内容(全部)
     * @param Request $request
     * @return TopicController
     */
    public function getTopicContentDate(Request $request){
        $topic_id = $request ->get('topic_id');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

        if(empty($topic_id)){
            return $this ->error('缺少参数');
        }

        $res  = ( new  CardModel()) ->getTopicContentDate($topic_id,$uuid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }

    }


    /**
     * 相关话题类容话题内容(最新)
     * @param Request $request
     * @return TopicController
     */
    public function getTopicContentNewDate(Request $request){
        $topic_id = $request ->get('topic_id');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];
        if(empty($topic_id)){
            return $this ->error('缺少参数');
        }

        $res  = ( new  CardModel()) ->getTopicContentNewDate($topic_id,$uuid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }

    }


    /**
     * 相关话题类容话题内容(最热)
     * @param Request $request
     * @return TopicController
     */
    public function getTopicContentHotDate(Request $request){
        $topic_id = $request ->get('topic_id');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

        if(empty($topic_id)){
            return $this ->error('缺少参数');
        }

        $res  = ( new  CardModel()) ->getTopicContentHotDate($topic_id,$uuid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }

    }

    /**
     * 话题内容详细
     * @param Request $request
     * @return TopicController
     */
    public function getTopicContentDesc(Request $request){
        $cid = $request ->get('cid');

        if(empty($cid)){
            return $this ->error('缺少参数');
        }

        $res  = ( new  CardModel()) ->getTopicContentDesc($cid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }
    }

}
